/*import java.util.Arrays;
import java.util.Scanner;
import java.util.Date;*/
import java.util.*;
//import java.sql.*;

import static java.lang.System.*;
/**
 * Created with IntelliJ IDEA.
 * User: 12629
 * Date: 2021/10/21
 * Time: 8:31
 * Description:
 */
public class TestDemo {

    public static void main(String[] args) {
        Date date = new Date();
    }

    public static void main5(String[] args) {
        int[] array = {1,2,3,4,5};
        out.println(Arrays.toString(array));
        Scanner scanner = new Scanner(System.in);
    }


    public static void main4(String[] args) {
        MyDoubleList myDoubleList = new MyDoubleList();
        myDoubleList.addLast(1);
        myDoubleList.display();
        System.out.println("============");
        //myDoubleList.addIndex(1,99);
        myDoubleList.remove(1);
        myDoubleList.display();
    }


    public static ListNode mergeTwoLists(ListNode headA, ListNode headB) {
        ListNode newHead = new ListNode(-1);
        ListNode tmp = newHead;

        while (headA != null && headB != null) {
            if(headA.val < headB.val) {
                tmp.next = headA;
                headA = headA.next;
            }else {
                tmp.next = headB;
                headB = headB.next;
            }
            tmp = tmp.next;
        }
        if(headA != null) {
            tmp.next = headA;
        }
        if(headB != null) {
            tmp.next = headB;
        }
        return newHead.next;
    }


    public static ListNode getIntersectionNode(ListNode headA, ListNode headB) {

        ListNode pl = headA;
        ListNode ps = headB;

        int lenA = 0;
        while (pl != null) {
            lenA++;
            pl = pl.next;
        }
        int lenB = 0;
        while (ps != null) {
            lenB++;
            ps = ps.next;
        }
        //pl = ps = null;
        pl = headA;
        ps = headB;
        int len = lenA-lenB;//差值步
        if(len < 0) {
            pl = headB;
            ps = headA;
            len = lenB-lenA;
        }
       // pl永远指向最长的那个链表  ps 永远指向 最短的那个链表  len
        while (len != 0) {
            pl = pl.next;
            len--;
        }

        while (pl!=null && ps != null && pl != ps) {
            pl = pl.next;
            ps = ps.next;
        }
        if(pl == ps && pl != null) {
            return pl;
        }
        return null;
    }

    public static void createCut(ListNode headA, ListNode headB) {
        headA.next.next = headB.next;
    }


    public static void main3(String[] args) {
        MyLinkedList myLinkedList1 = new MyLinkedList();
        myLinkedList1.addLast(1);
        myLinkedList1.addLast(12);
        myLinkedList1.addLast(32);
        myLinkedList1.addLast(42);

        MyLinkedList myLinkedList2 = new MyLinkedList();
        myLinkedList2.addLast(3);
        myLinkedList2.addLast(5);
        myLinkedList2.addLast(7);
        myLinkedList2.addLast(14);

        createCut(myLinkedList1.head,myLinkedList2.head);

        ListNode ret = getIntersectionNode(myLinkedList1.head,myLinkedList2.head);
        System.out.println(ret.val);

        /*ListNode newHead = mergeTwoLists(myLinkedList1.head,myLinkedList2.head);
        myLinkedList2.show2(newHead);*/

    }

    public static void main2(String[] args) {
        MyLinkedList myLinkedList = new MyLinkedList();
        //myLinkedList.createLinkedList();
        //myLinkedList.show();
        myLinkedList.addLast(1);
        myLinkedList.addLast(2);
        myLinkedList.addLast(3);
        myLinkedList.addLast(4);
        myLinkedList.show();//1 2 3 4 5

        System.out.println(myLinkedList.middleNode().val);

        /*ListNode ret = myLinkedList.reverseList();
        myLinkedList.show2(ret);// 5  4  3  2  1*/


        /*//myLinkedList.addIndex(4,199);
        myLinkedList.remove(1);//
        myLinkedList.show();// 2 3 4

        myLinkedList.clear();
        System.out.println("fdsfsafa");*/
    }



    public static void main1(String[] args) {
        MyArrayList myArrayList = new MyArrayList();//有了一个顺序表
        myArrayList.add(0,11);
        myArrayList.add(1,12);
        myArrayList.add(2,13);
        myArrayList.add(3,14);
        myArrayList.display();
        myArrayList.setPos(0,100);
        myArrayList.display();
        System.out.println("======================");
        myArrayList.clear();
        myArrayList.display();

        /*System.out.println(myArrayList.contains(1));
        System.out.println(myArrayList.search(11));
        System.out.println(myArrayList.search(12));
        System.out.println(myArrayList.search(14));

        System.out.println(myArrayList.getPos(0));
        System.out.println(myArrayList.getPos(2));
        System.out.println(myArrayList.getPos(3));
        System.out.println(myArrayList.size());*/
        //System.out.println(myArrayList.getPos(-1));
        //System.out.println(myArrayList.getPos(4));


        /*myArrayList.add(5,16);
        myArrayList.display();
*/
    }
}
